import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    //数据，相当于data
    state: {
        alert1: '',
        alert2: '',
        alert3: '',
        //这里是给接口使用的
        title: null,
        chatId: null,//聊天id
        chatType: null,//agent or chat
        newChatForOne: true,// 初始值,
        againSearch: false, //for have new chat name
        imageUrl: '' ,// 初始化为空字符串或其他默认值  
        activeChatItem: null,//相应智能体配置
    },
    getters: {

        chatId: state => state.chatId,
        chatType: state => state.chatType,
        getNewChatForOne: state => {
            return state.newChatForOne;
        }  //for newchat
    },
    //里面定义方法，操作state方发
    mutations: {
        setActiveChatItem(state, item) {  
            state.activeChatItem = item;  
          }, 
        setChatType(state, type) {  
            state.chatType = type;  
          }, //聊天的类型
        setImageUrl(state, newImageUrl) {
            state.imageUrl = newImageUrl;
        },
        setAgainSearch(state, value) {
            state.againSearch = value;
        }, //for have new chat name
        SET_NEW_CHAT_FOR_ONE(state, value) {
            state.newChatForOne = value;
        },//for create NewChat
        setChatId(state, chatId) {
            state.chatId = chatId;
            console.log(chatId)
        },  //更新聊天的id的
        setTitle(state, newTitle) {
            state.title = newTitle;
        },
        updateAlert(state, { index, value }) {
            switch (index) {
                case 1:
                    state.alert1 = value
                    break;
                case 2:
                    state.alert2 = value
                    break;
                case 3:
                    state.alert3 = value
                    break;
            }
        },
        setAlerts(state, { alert1, alert2, alert3 }) {
            state.alert1 = alert1;
            state.alert2 = alert2;
            state.alert3 = alert3;
        }
    },
    // 操作异步操作mutation
    actions: {
        updateAlert({ commit }, { index, value }) {
            commit('updateAlert', { index, value })
        },
        fetchAlerts({ commit }, { alert1, alert2, alert3 }) {
            commit('setAlerts', { alert1, alert2, alert3 });
        }
    },
    modules: {

    },
})